export {
	LIMITERS as BILLING_LIMITERS,
	FEATURES as BILLING_FEATURES,
} from '../server/plugins/billing/constants';

// #region TaskCategory/TaskType
/**
asset
hostVul
vul
ssl
weakness
aviliable
securityEvent
content
 */
const TASK = [
	{
		key: 'asset',
		label: '资产变动',
		taskTypes: [{ key: 'asset', label: '资产变动' }],
	},
	{
		key: 'weakness',
		label: '脆弱性',
		inJob: true,
		taskTypes: [
			{ inJob: true, key: 'vul', label: 'Web漏洞' },
			{ inJob: true, key: 'ssl', label: 'SSL安全' },
		],
	},
	{
		key: 'securityEvent',
		label: '安全事件',
		inJob: true,
		taskTypes: [
			{ inJob: true, key: 'securityEvent', label: '安全事件' },
			// { key: 'attackEvent', label: '攻击事件' },
		],
	},
	{
		key: 'content',
		label: '内容违规',
		inJob: true,
		taskTypes: [{ inJob: true, key: 'content', label: '内容违规' }],
	},
	{
		key: 'aviliable',
		label: '可用性',
		inJob: true,
		taskTypes: [
			{ inJob: true, key: 'http', label: 'HTTP' },
			{ inJob: true, key: 'ping', label: 'Ping' },
		],
	},
	{
		key: 'sitePortrait',
		label: '网站画像',
		taskTypes: [{ key: 'sitePortrait', label: '网站画像' }],
	},
];
export const ONCE_TASK = {
	vul: 'web漏洞',
	ssl: 'SSL安全',
	securityEvent: '安全事件',
	asset: '资产变动',
	content: '内容违规',
};
export const TASK_CATEGORY_KEYS = TASK.map(x => x.key);

export const JOB_TASK_CATEGORY_KEYS = TASK.map(x => x.key);

export const JOB_TASK_CATEGORY_KEY_LABEL_MAP = TASK.reduce((obj, category) => {
	if (category.inJob) obj[category.key] = category.label;
	return obj;
}, {});
// [ 'vul', 'ssl', 'securityEvent', 'content', 'http', 'ping' ]
export const JOB_TASK_TYPES = TASK.reduce((arr, x) => {
	x.taskTypes.forEach(task => {
		if (!task.inJob) return;
		arr.push(task.key);
	});
	return arr;
}, []);

export const JOB_TASK_TYPE_MAP = JOB_TASK_TYPES.reduce((obj, x) => {
	obj[x] = true;
	return obj;
}, {});

export const TASK_TYPES = TASK.reduce((arr, x) => {
	return arr.concat(x.taskTypes.map(x => x.key));
}, []);

export const AVILIABLE_TASK_MAP = TASK.find(
	x => x.key === 'aviliable'
).taskTypes.reduce((obj, x) => {
	obj[x.key] = true;
	return obj;
}, {});

export const TASK_KEY_LABEL_MAP = TASK.reduce((obj, category) => {
	category.taskTypes.forEach(task => {
		obj[task.key] = task.label;
	});
	return obj;
}, {});

export const TASK_CATEGORY_TYPES_MAP = TASK.reduce((obj, category) => {
	obj[category.key] = category.taskTypes.map(task => task.key);
	return obj;
}, {});

export const TASK_TYPE_CATEGORY_MAP = Object.entries(
	TASK_CATEGORY_TYPES_MAP
).reduce((obj, [category, types]) => {
	types.forEach(t => {
		obj[t] = category;
	});
	return obj;
}, {});

export const TASK_CATEGORY_KEY_LABEL_MAP = TASK.reduce((obj, category) => {
	obj[category.key] = category.label;
	return obj;
}, {});
// #endregion TaskCategory/TaskType

export const WARN_LEVEL_MAP = {
	5: '严重',
	4: '高危',
	3: '中危',
	2: '低危',
};
export const WARN_LEVEL_COLOR_MAP = {
	5: { label: '严重', color: '#A00000' },
	4: { label: '高危', color: '#E01010' },
	3: { label: '中危', color: '#F5A623' },
	2: { label: '低危', color: '#F8E71C' },
	1: { label: '安全', color: '#11AB4E' },
	0: { label: '未知', color: '#9B9B9B' },
};
export const INFORM_OPTIONS = [
	{
		value: 'email',
		label: '邮件',
	},
	{
		value: 'sms',
		label: '短信',
	},
	{
		value: 'wechat',
		label: '微信',
	},
	{
		value: 'inBox',
		label: '站内信',
	},
];
export const WARNING_DEDUCTION_RULE_MAP = {
	严重: 5,
	高危: 4,
	中危: 3,
	低危: 2,
};

export const SPEED_LEVEL_MAP = {
	high: '高速',
	medium: '快速',
	low: '普通',
};
export const VUL_PATTERN = {
	high: '仅高危',
	medium: '高、中、低危',
	low: '高、中、低危',
};
export const VUL_LEVEL_MAP = {
	严重: 5,
	高: 4,
	中: 3,
	低: 2,
};

export const VUL_LEVEL_NUM_LABEL_MAP = {
	5: '严重',
	4: '高',
	3: '中',
	2: '低',
};

export const VUL_LEVEL_EN_NUM_MAP = {
	critical: 5,
	high: 4,
	medium: 3,
	low: 2,
};
export const VUL_LEVEL_EN_CN_MAP = {
	critical: '严重',
	high: '高危',
	medium: '中危',
	low: '低危',
};

export const VUL_LEVEL_NUM_EN_MAP = {
	2: 'low',
	4: 'high',
	3: 'medium',
	5: 'critical',
};

export const LEVEL_NUM_LABEL_MAP = {
	5: '严重',
	4: '高危',
	3: '中危',
	2: '低危',
};

export const WEAKNESS_STATUS_MAP = {
	unknown: '未知',
	safe: '安全',
	warning: '威胁',
};

export const AVILIABLE_STATUS_MAP = {
	unknown: '未知',
	safe: '正常',
	warning: '异常',
};

export const ASSET_STATUS_MAP = {
	unknown: '无更新',
	safe: '无更新',
	warning: '已更新',
};

export const FREQ_UNIT_MAP = {
	m: '分钟',
	h: '小时',
	d: '天',
	w: '周',
	month: '月',
};

export const FREQUENCY_NUMBERS = Array.from(Array(59)).map((_, i) => i + 1);

export const FREQUENCY_UNIT_MAP = {
	s: '秒',
	m: '分钟',
	h: '小时',
	d: '天',
	w: '周',
	month: '月',
};

export const WEAKNESS_FREQUENCY_UNIT_MAP = {
	m: '分钟',
	h: '小时',
	d: '天',
	w: '周',
	month: '月',
};

export const HTTP_FREQUENCY_NUMBERS = Array.from(Array(60)).map(
	(_, i) => i + 1
);

export const HTTP_FREQUENCY_UNIT_MAP = {
	m: '分钟',
};

export const PING_FREQUENCY_NUMBERS = [2, 5, 10, 15, 30];

export const PING_FREQUENCY_UNIT_MAP = {
	m: '分钟',
};

export const NOTIFY_TYPE = {
	sms: '短信',
	email: '邮件',
	wechat: '微信',
};

export const CONTACT_TYPE = {
	phone: '电话',
	email: '邮件',
	wechat: '微信',
};

export const LOG_SOURCE_DICT = {
	front: '用户前台',
	back: '管理后台',
};
export const LOG_MODULE_DICT = {
	task: '监测任务',
	asset: '资产变动监测',
	job: '监测任务配置',
	vul: '漏洞扫描',
	assets: '资产扫描',
	ssl: 'SSL配置监测',
	aviliable: '可用性监控',
	content: '内容安全监测',
	alert: '告警/通知',
	ping: 'Ping监测',
	http: 'HTTP监测',
	'site-portrait': '网站画像',
	billing: '套餐/充值',
	user: '用户管理',
	news: '新闻/公告',
	cloud: '云防联动',
};
export const LOG_ACTION_DICT = {
	update: '更新',
	create: '新增',
	delete: '删除',
};

export const NODE_ID_LABEL_MAP2 = {
	'wuhan2-ctc1': '武汉电信',
	'xian2-ctc1': '西安电信',
	'dalian-ctc1': '大连电信', // v6
	'suqian-cuc1': '宿迁联通',
	'nanchang-ctc1': '南昌电信',
	'nanchang2-cuc1': '南昌联通',
	'zhuzhou-cuc1': '株洲联通',
	'hengyang-ctc1': '衡阳电信',
	'tianjin-ctc1': '天津电信',
	'xiangyang-cmc1': '襄阳移动',
};
export const NODE_ID_LABEL_MAP = [
	{
		abs_name: '昆明电信',
		area: 'kunming-ctc1',
	},
	{
		abs_name: '重庆联通',
		area: 'chongqing-cuc1',
	},
	{
		abs_name: '北京联通',
		area: 'beijing-cuc1',
	},
	{
		abs_name: '成都移动',
		area: 'chengdu-cmc1',
	},
	{
		index: 0,
		abs_name: '成都市移动',
		abs_id: '962c82b2345a44bca4545bf5c416d81b',
		area: 'chengdu-cmc',
	},
	{
		index: 1,
		abs_name: '呼和浩特市联通',
		abs_id: '74cd581869bd464ea79fa4151b89b6c5',
		area: 'huhehaote-cuc',
	},
	{
		index: 5,
		abs_name: '北京市联通',
		abs_id: '5bfd7d64b76a4957af2b5912e9c3ffe2',
		area: 'beijing-cuc',
	},
	{
		index: 7,
		abs_name: '西安市电信2',
		abs_id: '2c566c3f488d458b9602bc6492354d9d',
		area: 'tx-xian',
	},
	{
		index: 11,
		abs_name: '北京市移动',
		abs_id: '86eee42c789944e6816b023dcf997da6',
		area: 'beijing-cmc',
	},
	{
		index: 18,
		abs_name: '重庆市联通',
		abs_id: 'a7a9cb7e120a443095c095491e646f30',
		area: 'chongqing-cuc',
	},
	{
		index: 25,
		abs_name: '昆明市电信',
		abs_id: '42eee6996f6b40d49ebc5b736dcd02af',
		area: 'kunming-ctc',
	},
	{
		index: 8,
		abs_name: 'testcdn',
		abs_id: 'edf95ef24a514b49883ee089f60416b7',
		area: 'test-cdn',
	},
	{
		index: 2,
		abs_name: 'txhk',
		abs_id: '4d76661f8fc947a4a1f84791ad0571e0',
		area: 'tx-hk',
	},
	{
		index: 24,
		abs_name: '南昌市联通2',
		abs_id: 'a551b9a6be654d0e803050ff0b7d43f1',
		area: 'tx-nanchang',
	},
	{
		index: 3,
		abs_name: '武汉市电信2',
		abs_id: 'd1f5e203aead4943a096908d98ed48e9',
		area: 'tx-wuhan',
	},

	{
		index: 14,
		abs_name: '温州市电信',
		abs_id: 'd94e8f809a6f427a86e7fbfa3575af7b',
		area: 'wenzhou-ctc',
	},
	{
		index: 26,
		abs_name: '襄阳市移动',
		abs_id: '0c1a906cb26443868c5381450f4f2ae1',
		area: 'xiangyang-cmc',
	},
	{
		index: 10,
		abs_name: '云浮市电信',
		abs_id: '1b46cc02de4c4d24adf7232139da5faf',
		area: 'yunfu-ctc',
	},
]
	.sort((a, b) => a.index - b.index)
	.reduce((obj, { abs_name: name, area: key }) => {
		if (['testcdn', 'txhk'].includes(name)) return obj;
		obj[key] = name;
		return obj;
	}, {});

export const NODE_LABEL_ID_MAP = Object.entries(NODE_ID_LABEL_MAP).reduce(
	(obj, [key, val]) => {
		obj[val] = key;
		return obj;
	},
	{}
);

export const SITE_PORTRAIT_OP_REVERSE_MAP = {
	add: '移除',
	remove: '新增',
	copy: '移除',
	replace: '更新',
	move: '移动',
};

export const TRIGGER_KEY_LABEL_MAP = {
	schedule: '周期性',
	manual: '自定义单次',
};

export const VUL_TRIGGER_KEY_LABEL_MAP = {
	schedule: '周期性全量',
	scheduleIncrement: '周期性增量',
	manual: '自定义单次',
};

export const QUEUE_TASK_STATUS_MAP = {
	waiting: '等待调度',
	active: '正在检测',
	stopped: '检测停止',
	failed: '检测失败',
};
export const WARNING_SECURITYEVENT_MAP = {
	black_links: '暗链',
	cryjack: '挖矿',
	malscan: '挂马',
	broken_links: '坏链',
	foreign_links: '风险外链',
	icp: '未备案',
	keyword: '违规内容',
	domain: '风险域名',
};
export const WARNING_SSL_MAP = {
	certificate: '证书配置威胁',
	protocol: '协议漏洞',
};
export const WARNING_CONTENT_MAP = {
	keyword: '敏感词',
	protocol: '协议漏洞',
};

export const CHECK_CHANGE_TYPE = {
	text: '文本变更',
	structure: '结构变更',
	resource: '资源变更',
};

export const WARNING_CATEGORY_KEY_LABEL_MAP = {
	securityEvent: {
		black_links: '暗链',
		foreign_links: '风险外链',
		broken_links: '坏链',
		cryjack: '挖矿',
		malscan: '挂马',
	},
	ssl: {
		certificate: 'SSL证书配置',
		protocol: 'SSL协议漏洞',
	},
	asset: {
		subdomain: '子域名',
		port: '端口',
		portService: '端口服务',
	},
	vul: {
		file_upload: '文件上传',
		directory_listing: '目录浏览',
		xss: '跨站脚本攻击',
		directory_traversal: '目录穿越',
		code_execution: '代码执行',
		csrf: '跨站请求伪造',
		file_inclusion: '文件包含',
		injection: '注入漏洞',
		configuration: '配置风险',
		information_disclosure: '信息泄漏',
		command_execution: '命令执行',
		malware: '木马后门',
		webvul: 'Web应用程序漏洞',
	},
	content: {
		keyword: '敏感词',
		privacy_disclosure: '隐私信息',
	},
	checkChange: {
		keyword: '敏感词',
		changeType: '变更类型',
	},
	ipv6: {
		support: '支持IPv6',
		n_support: '不支持IPv6',
	},
	changeCheck: {
		structure: '结构变更',
		text: '文本变更',
		resource: '资源变更',
	},
};

export const SSL_CATEGORY_KEY_LABEL_MAP = WARNING_CATEGORY_KEY_LABEL_MAP.ssl;

export const SECURITY_EVENT_TYPE_MAP =
	WARNING_CATEGORY_KEY_LABEL_MAP.securityEvent;

export const VUL_TYPE_MAP = WARNING_CATEGORY_KEY_LABEL_MAP.vul;

export const ASSET_TYPE_MAP = WARNING_CATEGORY_KEY_LABEL_MAP.asset;

/**
 * 内容违规
 */
export const CONTENT_KEYWORD_TYPES = [
	{ idx: 9, key: 'chatgpt', label: 'ChatGPT' },
	{ idx: 1, key: 'politics', label: '政治' },
	{ idx: 2, key: 'pornography', label: '涉黄' },
	{ idx: 3, key: 'reaction', label: '反动' },
	{ idx: 4, key: 'gangland', label: '涉黑' },
	{ idx: 5, key: 'violence', label: '暴恐' },
	{ idx: 6, key: 'bet', label: '博彩' },
	{ idx: 7, key: 'livelihood', label: '民生' },
	{ idx: 8, key: 'others', label: '其他' },
];
export const CONTENT_KEYWORD_IDX_LABEL_MAP = CONTENT_KEYWORD_TYPES.reduce(
	(obj, x) => {
		obj[x.idx] = x.label;
		return obj;
	},
	{}
);
export const CONTENT_PRIVACY_DISCLOSURE_TYPES = [
	{ idx: 1, key: 'phoneNumber', label: '手机号' },
	{ idx: 2, key: 'bankCardNumber', label: '银行卡号' },
	{ idx: 3, key: 'emailAddress', label: '邮箱号' },
	{ idx: 4, key: 'idCardNumber', label: '身份证号' },
];
export const CONTENT_CONTENT_TYPE_TYPES = [
	{ idx: 1, key: 'text', label: '文本' },
	{ idx: 2, key: 'image', label: '图片' },
];
export const CONTENT_IDX_LABEL_MAP = {
	keyword: CONTENT_KEYWORD_TYPES.reduce((obj, x) => {
		obj[x.idx] = x.label;
		return obj;
	}, {}),
	privacy_disclosure: CONTENT_PRIVACY_DISCLOSURE_TYPES.reduce((obj, x) => {
		obj[x.idx] = x.label;
		return obj;
	}, {}),
	contentChange: CONTENT_CONTENT_TYPE_TYPES.reduce((obj, x) => {
		obj[x.idx] = x.label;
		return obj;
	}, {}),
};
